<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加表单</title>
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/easyui/demo/demo.css}">
    <script type="text/javascript" th:src="@{/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript" th:src="@{/easyui/locale/easyui-lang-zh_CN.js}"></script>
</head>
<body>
<form id="ff" method="post">
    <div style="margin-bottom:20px">
        <input class="easyui-textbox" label="学号:" name="studentNo" data-options="prompt:'请输入学号 ge:stu0001',required:true" style="width:100%;">
    </div>
    <div style="margin-bottom:20px">
        <input class="easyui-textbox" name="name" label="姓名:" data-options="prompt:'请输入姓名',required:true" style="width:100%;">
    </div>
    <div style="margin-bottom:20px">
        <input class="easyui-numberspinner" name="age" value="15" data-options="label:'年龄:',min:12,max:35" style="width:100%;">
    </div>
    <div style="margin-bottom:20px">
        <select class="easyui-combobox" name="gender" label="性别:" style="width:100%;">
            <option>男</option>
            <option>女</option>
        </select>
    </div>
    <div style="margin-bottom:20px">
        <input class="easyui-datetimebox" name="birthday" label="出生日期:" style="width:100%;">
    </div>
</form>
<script>
    function submitForm(){
        //请求后端的接口将数据提交到数据库中去
        $('#ff').form('submit',{
            url:"/student/addStudent.do",
            onSubmit:function(){
                //这一步是在提交表单之前需要做的事情？
                //==》先进行表单验证
                return $(this).form('enableValidation').form('validate');
            },
            success:function(data){
                //但是后端返回的是JSON字符串==》如果需要获取里面的属性 则将该字符串解析为对象
                //console.log(data)
                var parse = JSON.parse(data);
                //console.log(parse)
                if (parse.success === true){
                    //添加成功==》提示添加成功！！
                    $.messager.show({
                        title:'提示',
                        msg:parse.message,
                        timeout:1000
                    });
                    //刷新表格数据+关闭对话框
                    $('#dg').datagrid('reload');
                    $('#dlg').dialog('close');
                }else {
                    $.messager.alert('异常',parse.message,'error');
                }
            }
        });
    }
    function clearForm(){
        $('#ff').form('clear');
    }
</script>
</body>
</html>